package com.g2.mydysingle.controller;

import com.g2.mydysingle.dto.FilmDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;


/**
 * 处理所有页面的跳转
 */
@Api(tags = "页面跳转")
@Controller
@Slf4j
public class MainController {
    /**
     * templates下的子目录
     */
    private final static String BZH = "/bzh/";
    private final static String GHH = "/ghh/";
    private final static String LJX = "/ljx/";
    private final static String LPC = "/lpc/";
    private final static String LSM = "/lsm/";
    private final static String YSC = "/ysc/";
    private final static String MHG = "/mhg/";

    private final static String case1 = "bzh";
    private final static String case2 = "ghh";
    private final static String case3 = "ljx";
    private final static String case4 = "lpc";
    private final static String case5 = "lsm";
    private final static String case6 = "ysc";
    private final static String case7 = "mhg";

    /**
     * 自动跳转首页页面
     * @return
     */
    @GetMapping("/")
    @ApiOperation("自动跳转首页页面")
    public String index(){
        return "index";
    }

    /**
     * 处理页面间的跳转
     * @param target
     * @return
     */
    @GetMapping("/views/{target}")
    @ApiOperation("处理页面间的跳转")
    public String toView(@PathVariable String target){
        //跳转视图
        String views = null;
        String pre = target.substring(0,target.indexOf("_"));
        switch (pre){
            case case1:
                views = BZH + target;
                break;
            case case2:
                views = GHH + target;
                break;
            case case3:
                views = LJX + target;
                break;
            case case4:
                views = LPC + target;
                break;
            case case5:
                views = LSM + target;
                break;
            case case6:
                views = YSC + target;
                break;
            case case7:
                views = MHG + target;
                break;
            default:
                views = "/formatError";
                break;
        }
        return views;
    }

    /**
     * 测试带数据跳转页面
     * @param id
     * @return
     */
    @GetMapping("/edit/{id}")
    public ModelAndView edit(@PathVariable String id){
        log.info("我是传过来的数据--：" + id);

        //TODO
        //通过id去数据库查询这条数据记录
        FilmDTO dto = new FilmDTO();
        dto.setName("爱丽丝梦游仙境");
        dto.setDesc("《爱丽丝梦游仙境》（Alice in Wonderland）是迪士尼的一部3D立体电影，其灵感来自于英国童话大师刘易斯·卡罗尔的《爱丽斯漫游仙境》和《爱丽丝镜中奇遇记》。由蒂姆·波顿执导，米娅·华希科沃斯卡、约翰尼·德普、海伦娜·邦汉·卡特和安妮·海瑟薇等联袂出演。影片于2010年3月26日在中国内地上映。");

        //ModelAndView 使用这个来做页面跳转
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/ghh/ghh_page1");
        mv.addObject("dto",dto);
        return mv;
    }



}
